using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using TVC.Layout;

namespace TVC.Modules.Com
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class DPT : ModuleParent, IHostedApplication
    {
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        private Label label2;
        private TextBox txtROLE_NAME;
        private TextBox txtROLE_ID;
        private Label label1;
        private DataGridView dgvList;
        private Label label5;
        private Label label4;
        private Button btnRemove;
        private Button btnClear;
        private Button btnAdd;
        private Button btnFill;
        private ListBox libDptAssign;
        private ListBox libDepartment;
        private DataGridViewTextBoxColumn colROLE_ID;
        private DataGridViewTextBoxColumn colNAME;
        private BindingSource bisDA;
        private IContainer components;
        GridLayout layout = null;
        public DPT()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();
            _strType = "DPT";
        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        int idAllowEditLanguage = 1;
        int idEdit = 218;
        int idTransferIn = 219;
        int idTransferOut = 220;
        int idPrint = 221;

        protected override void AllowEditLanguage()
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    x.DoubleClick += Control_DoubleClick;
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    x.DoubleClick += Control_DoubleClick;
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            y.DoubleClick += Control_DoubleClick;
                    }
                }
            }

            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add(new MenuItem("Edit Language"));
            dgvList.MenuClick += dgvList_MenuClick;
            tabControl1.DoubleClick += tabMain_DoubleClick;
            dgvList.ContextMenu = menu;
        }

        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }
            //clsConfigurarion.GetLabel(this.ToString(), lbUserID, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDescription, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblLanguage, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDbDefault, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklRole, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklEmp, language);

            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idEdit)) objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));

            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idTransferIn)) objElements.Add(new HostedToolBarButton("clsTransfer In", new IconResourceHandle("Down.png"), "TI"));
            if (IsPermis(idTransferOut)) objElements.Add(new HostedToolBarButton("clsTransfer Out", new IconResourceHandle("Up.png"), "TO"));
            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idPrint)) objElements.Add(new HostedToolBarButton("Print", new IconResourceHandle("Print.png"), "P"));
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }

        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.colROLE_ID = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colNAME = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.bisDA = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.label5 = new Gizmox.WebGUI.Forms.Label();
            this.label4 = new Gizmox.WebGUI.Forms.Label();
            this.btnRemove = new Gizmox.WebGUI.Forms.Button();
            this.btnClear = new Gizmox.WebGUI.Forms.Button();
            this.btnAdd = new Gizmox.WebGUI.Forms.Button();
            this.btnFill = new Gizmox.WebGUI.Forms.Button();
            this.libDptAssign = new Gizmox.WebGUI.Forms.ListBox();
            this.libDepartment = new Gizmox.WebGUI.Forms.ListBox();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.txtROLE_NAME = new Gizmox.WebGUI.Forms.TextBox();
            this.txtROLE_ID = new Gizmox.WebGUI.Forms.TextBox();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDA)).BeginInit();
            this.tbDetail.SuspendLayout();
            this.SuspendLayout();
            // 
            // errProvider
            // 
            this.errProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(601, 442);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(593, 416);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowDrag = false;
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.Columns.AddRange(new Gizmox.WebGUI.Forms.DataGridViewColumn[] {
            this.colROLE_ID,
            this.colNAME});
            this.dgvList.DataSource = this.bisDA;
            this.dgvList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(593, 416);
            this.dgvList.TabIndex = 0;
            this.dgvList.RowHeaderMouseDoubleClick += new Gizmox.WebGUI.Forms.DataGridViewCellMouseEventHandler(this.dgvList_RowHeaderMouseDoubleClick);
            // 
            // colROLE_ID
            // 
            this.colROLE_ID.DataPropertyName = "ROLE_ID";
            this.colROLE_ID.DefaultCellStyle = dataGridViewCellStyle3;
            this.colROLE_ID.HeaderText = "Code";
            this.colROLE_ID.Name = "colROLE_ID";
            // 
            // colNAME
            // 
            this.colNAME.AutoSizeMode = Gizmox.WebGUI.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.colNAME.DataPropertyName = "ROLE_NAME";
            this.colNAME.DefaultCellStyle = dataGridViewCellStyle4;
            this.colNAME.HeaderText = "Description";
            this.colNAME.Name = "colNAME";
            // 
            // bisDA
            // 
            this.bisDA.DataSource = typeof(DTO.POGInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.label5);
            this.tbDetail.Controls.Add(this.label4);
            this.tbDetail.Controls.Add(this.btnRemove);
            this.tbDetail.Controls.Add(this.btnClear);
            this.tbDetail.Controls.Add(this.btnAdd);
            this.tbDetail.Controls.Add(this.btnFill);
            this.tbDetail.Controls.Add(this.libDptAssign);
            this.tbDetail.Controls.Add(this.libDepartment);
            this.tbDetail.Controls.Add(this.label2);
            this.tbDetail.Controls.Add(this.txtROLE_NAME);
            this.tbDetail.Controls.Add(this.txtROLE_ID);
            this.tbDetail.Controls.Add(this.label1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(593, 416);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(262, 97);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(56, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Department Assignment";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(16, 97);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(56, 13);
            this.label4.TabIndex = 0;
            this.label4.Text = "Department";
            // 
            // btnRemove
            // 
            this.btnRemove.Location = new System.Drawing.Point(199, 215);
            this.btnRemove.Name = "btnRemove";
            this.btnRemove.Size = new System.Drawing.Size(56, 23);
            this.btnRemove.TabIndex = 7;
            this.btnRemove.Text = "<";
            this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
            // 
            // btnClear
            // 
            this.btnClear.Location = new System.Drawing.Point(199, 255);
            this.btnClear.Name = "btnClear";
            this.btnClear.Size = new System.Drawing.Size(56, 23);
            this.btnClear.TabIndex = 8;
            this.btnClear.Text = "<<";
            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
            // 
            // btnAdd
            // 
            this.btnAdd.Location = new System.Drawing.Point(199, 175);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(56, 23);
            this.btnAdd.TabIndex = 6;
            this.btnAdd.Text = ">";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnFill
            // 
            this.btnFill.Location = new System.Drawing.Point(199, 135);
            this.btnFill.Name = "btnFill";
            this.btnFill.Size = new System.Drawing.Size(56, 23);
            this.btnFill.TabIndex = 5;
            this.btnFill.Text = ">>";
            this.btnFill.Click += new System.EventHandler(this.btnFill_Click);
            // 
            // libDptAssign
            // 
            this.libDptAssign.Location = new System.Drawing.Point(265, 110);
            this.libDptAssign.Name = "libDptAssign";
            this.libDptAssign.SelectionMode = Gizmox.WebGUI.Forms.SelectionMode.One;
            this.libDptAssign.Size = new System.Drawing.Size(169, 199);
            this.libDptAssign.TabIndex = 4;
            // 
            // libDepartment
            // 
            this.libDepartment.Location = new System.Drawing.Point(19, 110);
            this.libDepartment.Name = "libDepartment";
            this.libDepartment.SelectionMode = Gizmox.WebGUI.Forms.SelectionMode.One;
            this.libDepartment.Size = new System.Drawing.Size(169, 199);
            this.libDepartment.TabIndex = 3;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 41);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Description";
            // 
            // txtROLE_NAME
            // 
            this.txtROLE_NAME.AllowDrag = false;
            this.txtROLE_NAME.Enabled = false;
            this.txtROLE_NAME.Location = new System.Drawing.Point(105, 38);
            this.txtROLE_NAME.MaxLength = 100;
            this.txtROLE_NAME.Name = "txtROLE_NAME";
            this.txtROLE_NAME.Size = new System.Drawing.Size(329, 20);
            this.txtROLE_NAME.TabIndex = 1;
            // 
            // txtROLE_ID
            // 
            this.txtROLE_ID.AllowDrag = false;
            this.txtROLE_ID.Enabled = false;
            this.txtROLE_ID.Location = new System.Drawing.Point(105, 12);
            this.txtROLE_ID.MaxLength = 15;
            this.txtROLE_ID.Name = "txtROLE_ID";
            this.txtROLE_ID.Size = new System.Drawing.Size(100, 20);
            this.txtROLE_ID.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Code";
            // 
            // DPT
            // 
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Location = new System.Drawing.Point(0, -10);
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(607, 448);
            this.Load += new System.EventHandler(this.DA_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDA)).EndInit();
            this.tbDetail.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion


        #region IHostedApplication Members

        public void InitializeApplication()
        {
        }
        public void addRecord()
        {

        }
        public void SetObject(object obj)
        {
        }


        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                string strAction = (string)objButton.Tag;
                BUS.POGControl ctr = new BUS.POGControl();
                switch (strAction)
                {
                    case "C":
                        tabControl1.SelectedTab = tbDetail;
                        RefreshForm("");
                        EnableForm(true);
                        break;
                    case "A":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.POGInfo info = new DTO.POGInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            if (txtROLE_ID.Text != info.ROLE_ID)
                                SetData(info);
                            EnableForm(true);
                            txtROLE_ID.ReadOnly = true;
                            txtROLE_NAME.ReadOnly = true;
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "S":
                        if (layout == null)
                            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", "POG");
                        layout.GetUpDGV(dgvList);
                        layout.SaveLayout();
                        saveRecord(txtROLE_ID);

                        break;
                    case "TI":
                        Forms.frmTransferIn frmTI = new Forms.frmTransferIn(_strType, GetMainForm());
                        frmTI.ShowDialog();
                        break;
                    case "TO":
                        Forms.frmTransferOut frmTO = new Forms.frmTransferOut(_strType, GetMainForm());
                        frmTO.Show();
                        break;
                    case "R":
                        RefreshList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.POGInfo info = new DTO.POGInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            DataTable dt = DTO.POGInfo.ToDataTable();
                            dt.Rows.Add(info.ToDataRow(dt));
                            DataSet ds = new DataSet();
                            ds.Tables.Add(dt);
                            MainForm main = GetMainForm();
                            if (main != null)
                                main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
                _processStatus = strAction;
                if (sErr == "")
                    ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        private void RefreshList()
        {
            GetMainForm().LoadDataTable("POG");
            Rebind();
            if (layout == null)
                layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", "POG");
            layout.ResetLayout();
            layout.SetUpDGV(dgvList);
        }



        public override void saveRecord(Control keyControl, bool isDraft = false)
        {
            BUS.DepartmentsControl ctr = new BUS.DepartmentsControl();
            if (tabControl1.SelectedTab == tbDetail)
            {
                DTO.POGInfo info = GetData();
                string[] arrrole = GetGroup();
                if (_processStatus == "A")
                {
                    sErr = ctr.Delete(info.ROLE_ID);
					if(arrrole !=null)
					{
						foreach (string role in arrrole)
						{
							DTO.DepartmentsInfo daoginf = new DTO.DepartmentsInfo(info.ROLE_ID, role, "");
							ctr.InsertUpdate(daoginf);
						}
					}
                    if (sErr == "") MessageBox.Show("Update records successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    else MessageBox.Show(sErr, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                ThrowMsg(sErr);

            }
        }
        private void Rebind()
        {
            bisDA.DataSource = GetMainForm().GetTable("POG");
        }


        private DTO.POGInfo GetData()
        {
            return new DTO.POGInfo() { ROLE_ID = txtROLE_ID.Text, ROLE_NAME = txtROLE_NAME.Text };

        }

        private void EnableForm(bool p)
        {
            txtROLE_ID.ReadOnly = !p;
            txtROLE_NAME.ReadOnly = !p;
            libDepartment.Enabled = p;
            libDptAssign.Enabled = p;
            btnAdd.Enabled = p;
            btnClear.Enabled = p;
            btnFill.Enabled = p;
            btnRemove.Enabled = p;
        }

        private void SetData(DTO.POGInfo info)
        {
            txtROLE_ID.Text = info.ROLE_ID;
            txtROLE_NAME.Text = info.ROLE_NAME;
            SetGroup(info);
        }

        private void RefreshForm(string str)
        {
            txtROLE_ID.Text = str;
            txtROLE_NAME.Text = str;
            ClearGroup();
        }

        private string[] GetGroup()
        {
            if (libDptAssign.Items.Count == 0)
                return null;
            string[] role = new string[libDptAssign.Items.Count];
            for (int i = 0; i < libDptAssign.Items.Count; i++)
            {
                role[i] = libDptAssign.Items[i].ToString();
            }
            return role;
        }
        private void SetGroup(DTO.POGInfo info)
        {
            BUS.DepartmentsControl ctr = new BUS.DepartmentsControl();
            DataTable dt = ctr.GetAll(ref sErr, info.ROLE_ID);
            foreach (DataRow row in dt.Rows)
            {
                libDepartment.Items.Remove(row["DPT_ID"].ToString());
                if (!libDptAssign.Items.Contains(row["DPT_ID"].ToString()))
                    libDptAssign.Items.Add(row["DPT_ID"].ToString());
            }
        }
        private void ClearGroup()
        {
            string busId = GetMainForm().PODInfo.Business_ID;
            string connect = Properties.Settings.Default.HLConnectString; ;

            BUS.DepartmentsControl ctr = new BUS.DepartmentsControl();
            DataTable dt = ctr.getListInSub(busId, ref sErr, connect);
            libDptAssign.Items.Clear();
            foreach (DataRow row in dt.Rows)
            {
                if (!libDepartment.Items.Contains(row["CODE"].ToString()))
                    libDepartment.Items.Add(row["CODE"].ToString());
            }
        }

        #endregion

        private void DA_Load(object sender, EventArgs e)
        {
            dgvList.AutoGenerateColumns = false;
            if (!GetMainForm().IsContainsTables("POG")) GetMainForm().LoadDataTable("POG");
            Rebind();
            EnableForm(false);
            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", "POG");
            //layout.LoadLayout();
            layout.SetUpDGV(dgvList);
            RefreshForm("");
            if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
                AllowEditLanguage();
        }

        private void dgvList_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.POGInfo info = new DTO.POGInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                SetData(info);
                EnableForm(false);
                tabControl1.SelectedTab = tbDetail;
                _processStatus = "V";
            }
        }

        private void btnFill_Click(object sender, EventArgs e)
        {
            if (libDepartment.Items.Count > 0)
                for (int i = libDepartment.Items.Count - 1; i >= 0; i--)
                {
                    string obj = libDepartment.Items[i].ToString();
                    libDepartment.Items.Remove(obj);
                    libDptAssign.Items.Add(obj);
                }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (libDepartment.SelectedItem != null)
            {
                string obj = libDepartment.SelectedItem.ToString();
                libDptAssign.Items.Add(obj);
                libDepartment.Items.Remove(obj);

            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (libDptAssign.SelectedItem != null)
            {
                string obj = libDptAssign.SelectedItem.ToString();
                libDepartment.Items.Add(obj);
                libDptAssign.Items.Remove(obj);

            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            if (libDptAssign.Items.Count > 0)
                for (int i = libDptAssign.Items.Count - 1; i >= 0; i--)
                {
                    string obj = libDptAssign.Items[i].ToString();
                    libDptAssign.Items.Remove(obj);
                    libDepartment.Items.Add(obj);
                }
        }

    }
}
